package com.kilon.workfaq.rest;

import com.kilon.workfaq.entity.CategoryPo;
import com.kilon.workfaq.service.read.CategoryReadService;
import com.kilon.workfaq.service.write.CategoryWriteService;
import com.kilon.workfaq.util.ResultBean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 博客分类表(Category)表控制层
 *
 * @author makejava
 * @since 2023-02-22 23:24:02
 */
@RestController
@RequestMapping("category")
public class CategoryRestService extends ResultBean {
    /**
     * 服务对象
     */
    @Resource
    private CategoryReadService categoryReadService;
    @Resource
    private CategoryWriteService categoryWriteService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("selectOne")
    public CategoryPo selectOne(String id) {
        return this.categoryReadService.queryById(id);
    }

    @PostMapping("queryAll")
    public List<CategoryPo> selectAll(CategoryPo categoryPo) {
        return this.categoryReadService.queryAll(categoryPo);
    }

    /**
     * 新增项目
     *
     * @return
     */
    @PostMapping("addCategory")
    public void addCategory(CategoryPo categoryPo) {
        //这里添加自定义条件
        this.categoryWriteService.insert(categoryPo);
    }

    /**
     * 更新项目
     *
     * @return
     */
    @PostMapping("updateProject")
    public void updateCategory(CategoryPo categoryPo) {
        //这里添加自定义条件
        if (this.categoryWriteService.update(categoryPo)) {
            //setResultData("更新成功");
        } else {
            //setErrorMsg("更新出错");
        }
    }

    /**
     * 删除项目
     *
     * @return
     */
    @PostMapping("dropCategory")
    public void dropCategory(CategoryPo categoryPo) {
        if (this.categoryWriteService.deleteById(categoryPo)) {
            //setResultData("删除成功");
        } else {
            //setErrorMsg("删除出错");
        }
    }
}
